//
//  WineFriendsNetwork.m
//  Shengzhuli
//
//  Created by 卡忙科技 on 16/9/13.
//  Copyright © 2016年 kamangkeji. All rights reserved.
//

#import "WineFriendsNetwork.h"
#import "GFXNetworkHandle.h"
#import "AddressBookModel.h"
#import "FriendsDetailModel.h"

NSString * const WineFirends = @"auth/user/list/friend";//好友列表
NSString * const SelectFirends = @"auth/member/search";//查找好友
NSString * const ApplyAddFirends = @"auth/member/send/add/friend/apply";//申请加好友
NSString * const ApplyFriendLists = @"auth/member/list/add/friend/apply";//申请列表
NSString * const AgreeAddFriends = @"auth/member/agree/add/friend/apply";//添加好友
NSString * const WineFriendsInfo = @"auth/member/info";//酒友信息
NSString * const ChatWithShopAdd = @"auth/user/add/shop/friend";//跟商家聊天加好友

NSString * const UpLoadAddressBook = @"auth/user/list/addressBook";//上传手机通讯录
NSString * const Invitation = @"auth/invitation/addressBook";//上传手机通讯录
NSString * const NearFriends = @"auth/user/listOrderByGps";//附近酒友
NSString * const WineFriendsCir = @"auth/user/cricle/list";//酒友圈
NSString * const PublicWineFriendsCir = @"auth/user/add/circle";//发布酒友圈

@implementation WineFriendsNetwork

+ (void)getWineFirendsWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,NSArray *friends))response
{
    [[GFXNetworkHandle shareHandle]post:WineFirends params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            NSMutableArray *friends = [NSMutableArray array];
            for (NSDictionary *dict in json[@"result"]) {
                EaseUserModel *model = [[EaseUserModel alloc]initWithBuddy:dict[@"mobilePhone"]];
                model.nickname = dict[@"nickName"];
                model.avatarURLPath = dict[@"portraitUrl"];
                model.personalizedSignature = dict[@"personalizedSignature"];
                model.ID = [dict[@"id"] integerValue];
                [friends addObject:model];
            }
            response(YES,json[@"message"],friends);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil);
    }];
}

+ (void)selectFirendsWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,NSArray *friends))response
{
    [[GFXNetworkHandle shareHandle]post:SelectFirends params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            NSMutableArray *friends = [NSMutableArray array];
            for (NSDictionary *dict in json[@"result"]) {
                EaseUserModel *model = [[EaseUserModel alloc]initWithBuddy:dict[@"mobilePhone"]];
                model.nickname = dict[@"nickName"];
                model.avatarURLPath = dict[@"portraitUrl"];
                model.personalizedSignature = dict[@"personalizedSignature"];
                [friends addObject:model];
            }
            response(YES,json[@"message"],friends);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil);
    }];
}

+ (void)getApplyFirendListsWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,NSArray *friends))response
{
    [[GFXNetworkHandle shareHandle]post:ApplyFriendLists params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            NSMutableArray *lists = [NSMutableArray array];
            for (NSDictionary *dict in json[@"result"]) {
                EaseUserModel *model = [[EaseUserModel alloc]initWithBuddy:dict[@"mobilePhone"]];
                model.nickname = dict[@"nickName"];
                model.avatarURLPath = dict[@"portraitUrl"];
                model.personalizedSignature = dict[@"personalizedSignature"];
                model.isFriend = [dict[@"isFriend"] integerValue];
                model.addFriendApplyId = [dict[@"addFriendApplyId"] integerValue];
                model.isApply = YES;
                [lists addObject:model];
            }
            response(YES,json[@"message"],lists);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil);
    }];
}

+ (void)agreeAddfriendsWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg))response
{
    [[GFXNetworkHandle shareHandle]post:AgreeAddFriends params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            response(YES,json[@"message"]);
        }else{
            response(NO,json[@"message"]);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError);
    }];
}

+ (void)getWineFriendsInfoWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,FriendsDetailModel *model))response
{
    [[GFXNetworkHandle shareHandle]post:WineFriendsInfo params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            FriendsDetailModel *model = [FriendsDetailModel objectWithDict:json[@"result"]];
            response(YES,json[@"message"],model);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil);
    }];
}

+ (void)applyAddFriendsWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg))response
{
    [[GFXNetworkHandle shareHandle]post:ApplyAddFirends params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            response(YES,json[@"message"]);
        }else{
            response(NO,json[@"message"]);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError);
    }];
}

+ (void)chatWithShopAddWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,NSString *mobilePhone,NSString *nickName))response
{
    [[GFXNetworkHandle shareHandle]post:ChatWithShopAdd params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            response(YES,json[@"message"],json[@"result"][@"mobilePhone"],json[@"result"][@"nickName"]);
        }else{
            response(NO,json[@"message"],nil,nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil,nil);
    }];
}

+ (void)uploadAddressBookWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,NSArray *addresses))response
{
    [[GFXNetworkHandle shareHandle]post:UpLoadAddressBook params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            NSMutableArray *addresses = [NSMutableArray array];
            for (NSDictionary *dict in json[@"result"]) {
                AddressBookModel *model = [AddressBookModel objectWithDict:dict];
                [addresses addObject:model];
            }
            response(YES,json[@"message"],addresses);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil);
    }];
}

+ (void)invitationWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg))response
{
    [[GFXNetworkHandle shareHandle]post:Invitation params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            response(YES,json[@"message"]);
        }else{
            response(NO,json[@"message"]);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError);
    }];
}

+ (void)getNearWineFriendsWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,NSArray *sources))response
{
    [[GFXNetworkHandle shareHandle]post:NearFriends params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            NSMutableArray *friends = [NSMutableArray array];
            for (NSDictionary *dict in json[@"result"]) {
                FriendsDetailModel *model = [FriendsDetailModel objectWithDict:dict];
                [friends addObject:model];
            }
            response(YES,json[@"message"],friends);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil);
    }];
}

+ (void)getWineFriendsCirListWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,NSArray *sources))response
{
    [[GFXNetworkHandle shareHandle]post:WineFriendsCir params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            NSMutableArray *friends = [NSMutableArray array];
            for (NSDictionary *dict in json[@"result"]) {
                FriendsDetailModel *model = [FriendsDetailModel objectWithDict:dict];
                [friends addObject:model];
            }
            response(YES,json[@"message"],friends);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil);
    }];
}

+ (void)publicWineFriendsCirWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg))response
{
    [[GFXNetworkHandle shareHandle]post:PublicWineFriendsCir params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            response(YES,json[@"message"]);
        }else{
            response(NO,json[@"message"]);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError);
    }];
}


@end
